<?php
class QuartosController extends AppController {

	var $name = 'Quartos';
	var $helpers = array('Html', 'Form','Tools');

	function index() {
		$this->Quarto->recursive = 0;
		$this->set('quartos', $this->paginate());
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid Quarto.', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->set('quarto', $this->Quarto->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->Quarto->create();
			if ($this->Quarto->save($this->data)) {
				$this->Session->setFlash(__('The Quarto has been saved', true));
				$this->redirect(array('action'=>'index'));
			} else {
				$this->Session->setFlash(__('The Quarto could not be saved. Please, try again.', true));
			}
		}
		$fotos = $this->Quarto->Foto->find('list');
		$itens = $this->Quarto->Item->find('list');
		$estabelecimentos = $this->Quarto->Estabelecimento->find('list');
		$categorias = $this->Quarto->Categoria->find('list');
		$this->set(compact('fotos', 'itens', 'estabelecimentos', 'categorias'));
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid Quarto', true));
			$this->redirect(array('action'=>'index'));
		}
		if (!empty($this->data)) {
			if ($this->Quarto->save($this->data)) {
				$this->Session->setFlash(__('The Quarto has been saved', true));
				$this->redirect(array('action'=>'index'));
			} else {
				$this->Session->setFlash(__('The Quarto could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Quarto->read(null, $id);
		}
		$fotos = $this->Quarto->Foto->find('list');
		$itens = $this->Quarto->Item->find('list');
		$estabelecimentos = $this->Quarto->Estabelecimento->find('list');
		$categorias = $this->Quarto->Categoria->find('list');
		$this->set(compact('fotos','itens','estabelecimentos','categorias'));
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for Quarto', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->Quarto->del($id)) {
			$this->Session->setFlash(__('Quarto deleted', true));
			$this->redirect(array('action'=>'index'));
		}
	}


	function admin_index() {
		$this->Quarto->recursive = 0;
		$this->set('quartos', $this->paginate());
	}

	function admin_view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid Quarto.', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->set('quarto', $this->Quarto->read(null, $id));
	}

	function admin_add() {
		if (!empty($this->data)) {
			$this->Quarto->create();
			if ($this->Quarto->save($this->data)) {
				$this->Session->setFlash(__('The Quarto has been saved', true));
				$this->redirect(array('action'=>'index'));
			} else {
				$this->Session->setFlash(__('The Quarto could not be saved. Please, try again.', true));
			}
		}
		$fotos = $this->Quarto->Foto->find('list');
		$itens = $this->Quarto->Item->find('list');
		$estabelecimentos = $this->Quarto->Estabelecimento->find('list');
		$categorias = $this->Quarto->Categoria->find('list');
		$this->set(compact('fotos', 'itens', 'estabelecimentos', 'categorias'));
	}

	function admin_edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid Quarto', true));
			$this->redirect(array('action'=>'index'));
		}
		if (!empty($this->data)) {
			if ($this->Quarto->save($this->data)) {
				$this->Session->setFlash(__('The Quarto has been saved', true));
				$this->redirect(array('action'=>'index'));
			} else {
				$this->Session->setFlash(__('The Quarto could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Quarto->read(null, $id);
		}
		$fotos = $this->Quarto->Foto->find('list');
		$itens = $this->Quarto->Item->find('list');
		$estabelecimentos = $this->Quarto->Estabelecimento->find('list');
		$categorias = $this->Quarto->Categoria->find('list');
		$this->set(compact('fotos','itens','estabelecimentos','categorias'));
	}

	function admin_delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for Quarto', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->Quarto->del($id)) {
			$this->Session->setFlash(__('Quarto deleted', true));
			$this->redirect(array('action'=>'index'));
		}
	}

}
?>